package com.atguigu.spzx.model.vo.common;

import lombok.Data;

/**
 * @author dyl
 * @version 1.0
 * @description:
 * @date 2024/12/24 19:01
 */
@Data
public class Result<T> {
    private Integer code;
    private T data;
    private String message;

    public static <T> Result<T> build(T data) {
        Result<T> result = new Result<>();
        result.data = data;
        return result;
    }

    public static <T> Result<T> build(Integer code, String message, T data) {
        Result<T> result = new Result<>();
        result.data = data;
        result.code = code;
        result.message = message;
        return result;
    }

    public static <T> Result<T> build() {
        return build(null);
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = build(data);
        result.code = ResultEnum.SUCCESS.getCode();
        result.message = ResultEnum.SUCCESS.getMessage();
        return result;
    }

    public static <T> Result<T> ok() {
        Result<T> result = build();
        result.code = ResultEnum.SUCCESS.getCode();
        result.message = ResultEnum.SUCCESS.getMessage();
        return result;
    }

    public static <T> Result<T> failed(ResultEnum resultEnum) {
        Result<T> result = build();
        result.code = resultEnum.getCode();
        result.message = resultEnum.getMessage();
        return result;
    }

    public static <T> Result<T> failed(String message) {
        Result<T> result = build();
        result.code = ResultEnum.FAILED.getCode();
        result.message = message;
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = build();
        result.code = ResultEnum.ERROR.getCode();
        result.message = ResultEnum.ERROR.getMessage();
        return result;
    }
}
